#include "stm32f10x.h"                  // Device header
#include "OLED.h"
#include "bsp_Timer.h"
#include "usart2.h"
#include "jy61p.h"
#include "bsp_game.h"
/*
		接口说明
   STM32	  外设
	PA2-----JY61P的RX
	PA3-----JY61P的TX
	PB8-----OLED的SCL
	PB9-----OLED的SDA
*/

/**
  * 坐标轴定义：
  * 左上角为(0, 0)点
  * 横向向右为X轴，取值范围：0~127
  * 纵向向下为Y轴，取值范围：0~63
  * 
  *       0             X轴           127 
  *      .------------------------------->
  *    0 |				2
  *      |
  *      |
  *      |
  *  Y轴 |
  *      |
  *      |   35              123
  *      |
  *   63 |				59
  *      v
  * 
  */

uint8_t s = 0;
uint8_t m = 0;

uint16_t Time;

int main(void)
{

	OLED_Init();
	usart2_Init(9600);
	Timer_Init();
	Game_map_Init();
	
	while (1)
	{
		Snak_Dir();
		
		/*OLED显示角度*/
		OLED_ShowSignedNum(2,15,Roll,4,OLED_6X8);
		OLED_ShowSignedNum(2,23,Pitch,4,OLED_6X8);
		OLED_ShowSignedNum(2,31,Yaw,4,OLED_6X8);
		OLED_ShowSignedNum(2,39,dir,4,OLED_6X8);
		OLED_Snak_Move(123, 2 , 38, 30);
		OLED_Snak_Food(45, 32);
		OLED_Update();
	}
}

void TIM2_IRQHandler(void)
{
	if (TIM_GetITStatus(TIM2, TIM_IT_Update) == SET)
	{
		Time++;
		Time_Add(&Time, &s, &m);	
		TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
	}
}
